/*
 Copyright (C) 2008  Maurizio Monticelli

 This program is free software; you can redistribute it and/or modify it under the terms of the 
 GNU General Public License as published by the Free Software Foundation; either version 2 of the 
 License, or (at your option) any later version.

 This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without 
 even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General 
 Public License for more details.

 You should have received a copy of the GNU General Public License along with this program; if not, write 
 to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA 
*/

package ch.justdoit.andriodrpncalc.view;

import android.content.Context;
import android.widget.AbsoluteLayout;
import ch.justdoit.andriodrpncalc.model.Model;
import ch.justdoit.andriodrpncalc.model.command.EvaluateCommand;
import ch.justdoit.andriodrpncalc.view.buttons.*;

public class KeyControl extends AbsoluteLayout{
	private Model model;
	
	public int WIDTH = 106;
	public int HEIGHT = 160;
	
	
	
	public KeyControl(Context context,  Model _model) {
		super(context);
		model = _model;
		
		ButtonGroup toggleButtonGroup = new ButtonGroup();
		
        int y = 0;
        int x = 0;


        // row 1

		ButtonExpression btnExpression = new ButtonExpression(context, model);
		model.mView.registerSecondButtons(btnExpression);
		addView(btnExpression, 
    			new AbsoluteLayout.LayoutParams(btnExpression.WIDTH, btnExpression.HEIGHT, x , y)
    	);
		y = y + btnExpression.HEIGHT;
		
		// ROW 2
		

		ButtonCommand btnEval = new ButtonCommand(context, model, new EvaluateCommand(model));
		addView(btnEval, 
    			new AbsoluteLayout.LayoutParams(btnEval.WIDTH, btnEval.HEIGHT, x, y)
    	);
		y = y + btnEval.HEIGHT;
		
		// ROW 3
		
		
		ThirdButton btnThird = new ThirdButton(context, model, toggleButtonGroup);
		addView(btnThird, 
    			new AbsoluteLayout.LayoutParams(btnThird.WIDTH, btnThird.HEIGHT, x, y)
    	);
		
		y = y + btnThird.HEIGHT;
		
		// ROW 4
		
		SecondButton btnSecond = new SecondButton(context, model, toggleButtonGroup);
		addView(btnSecond, 
    			new AbsoluteLayout.LayoutParams(btnSecond.WIDTH, btnSecond.HEIGHT, x, y)
    	);
		y = y + btnSecond.HEIGHT;
		x = x + btnSecond.WIDTH;
		
		WIDTH = x;
		HEIGHT = y;
	}
	
	

}
